import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin, bytecodePlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'
// 按需引入 element-plus 
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default defineConfig({
	main: {
		plugins: [externalizeDepsPlugin(), bytecodePlugin()]
	},
	preload: {
		plugins: [externalizeDepsPlugin(), bytecodePlugin()]
	},
	renderer: {
		resolve: {
			alias: {
				'@renderer': resolve('src/renderer/src')
			}
		},
		server: {
			proxy: {
				"/api": {
					target: 'http://uat.crm.xuexiluxian.cn',
					changeOrigin: true,
					rewrite: path => path.replace(/^\/api/, '')
				}
			}
		},
		plugins: [
			vue(),
			AutoImport({
				resolvers: [ElementPlusResolver()],
				// 将 d.ts 文件生成在 src 目录下
				dts: 'src/auto-imports.d.ts',
			}),
			Components({
				resolvers: [ElementPlusResolver()],
				// 将 d.ts 文件生成在 src 目录下
				dts: 'src/components.d.ts',
			}),
		]
	}
})
